package com.jp.knowledge.view;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.jp.knowledge.R;

/**
 * Created by 528787067@qq.com on 2017/4/18.
 */

public class TeamCircleTopView extends FrameLayout implements View.OnClickListener {

    private int selectedItemIndex;

    private Context mContext;
    private View contentView;
    private TextView leftBtn;
    private TextView rightBtn;

    public TeamCircleTopView(Context context) {
        super(context);
        mContext = context;
        init();
    }

    private void init(){
        contentView = inflate(mContext, R.layout.team_circle_top_view, this);
        leftBtn = (TextView) contentView.findViewById(R.id.team_circle_dynamic);
        rightBtn = (TextView) contentView.findViewById(R.id.team_circle_library);

        leftBtn.setOnClickListener(this);
        rightBtn.setOnClickListener(this);

        selectedItemIndex = 0;
    }

    @Override
    public void onClick(View v) {
        if(v == leftBtn && selectedItemIndex == 1){
            selectedItemIndex = 0;
            leftBtn.setTextColor(getResources().getColor(R.color.theme_color));
            leftBtn.setBackground(getResources().getDrawable(R.drawable.team_circle_top_btn_left_selected));
            rightBtn.setTextColor(getResources().getColor(R.color.font_gray_think));
            rightBtn.setBackground(getResources().getDrawable(R.drawable.team_circle_top_btn_right_normal));
            if(this.onItemSelectedListener != null)
                this.onItemSelectedListener.onItemSelected(selectedItemIndex);
        } else if(v == rightBtn && selectedItemIndex == 0){
            selectedItemIndex = 1;
            leftBtn.setTextColor(getResources().getColor(R.color.font_gray_think));
            leftBtn.setBackground(getResources().getDrawable(R.drawable.team_circle_top_btn_left_normal));
            rightBtn.setTextColor(getResources().getColor(R.color.theme_color));
            rightBtn.setBackground(getResources().getDrawable(R.drawable.team_circle_top_btn_right_selected));
            if(this.onItemSelectedListener != null)
                this.onItemSelectedListener.onItemSelected(selectedItemIndex);
        }
    }

    public int getSelectedItemIndex(){
        return this.selectedItemIndex;
    }

    private OnItemSelectedListener onItemSelectedListener;
    public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListener){
        this.onItemSelectedListener = onItemSelectedListener;
    }
    public interface OnItemSelectedListener{
        void onItemSelected(int index);
    }
}
